package xps.and.uudaijia.userclient.util;

import android.content.Context;
import android.util.Log;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.model.LatLng;
import com.jude.utils.JUtils;

/**
 * 为应用提供一个全局的位置信息
 * */
public class GlobalPositionInfo {
    private String TAG = getClass().getSimpleName();
    public LocationClient mLocationClient;
    private BDLocationListener myListener = new GlobalPositionInfo.MyLocationListener();
    public BDLocation bdLocation = null;
    private Context context;

    public GlobalPositionInfo(Context context) {
        this.mLocationClient = new LocationClient(context);
        this.mLocationClient.registerLocationListener(myListener);
        initLocation();
    }

    public class MyLocationListener implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            bdLocation = location;
            Log.e("GlobalPositionInfo",location.getLatitude()+"---getLatitude");
            Log.e("GlobalPositionInfo",location.getLongitude()+"--getLongitude");
        }

        @Override
        public void onConnectHotSpotMessage(String s, int i) {

        }
    }

    private void initLocation() {
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType("bd09ll");
        option.setScanSpan(0);
        option.setIsNeedAddress(true);
        option.setOpenGps(true);
        option.setLocationNotify(false);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        option.setIgnoreKillProcess(false);
        option.SetIgnoreCacheException(false);
        option.setEnableSimulateGps(false);
        mLocationClient.setLocOption(option);
        if (!mLocationClient.isStarted())
            mLocationClient.start();
    }

}
